<?php

Class LoadConfigs
{
    protected $_options = array();
	public $dbObject;
	public $path = './';
	
	
	public function __construct()
	{
        $this->path = PATH;
		if (strpos($_SERVER["SERVER_NAME"], "localhost") >= 0) {
            include_once($this->path . "/config/development.php");
			$configs = new Development;
			
        } else {
            include_once($this->path . "/config/production.php");
			$configs = new Production;
        }
		$this->_options = $configs->options;
		include_once($this->path . '/classes/dbModule.php');
		include_once($this->path . '/classes/membersModule.php');
		$this->dbOpenConnection();
    }
	
	private function _clean($elems)
	{ 
		if(!is_array($elems)) 
			$elems = htmlentities($elems, ENT_QUOTES, "UTF-8"); 
		else 
			foreach ($elems as $key => $value) 
				$elems[$key] = $this->_clean($value); 
		
		return $elems; 
	}
	
	public function getAllParams()
	{
		$params = $_POST;
		$result = $this->_clean($params);
		
		return $result;
	}
	
	private function dbOpenConnection()
	{
		$this->_options["dbConn"] = mysql_connect(
				$this->_options["dbConfig"]["server"] . ":".$this->_options["dbConfig"]["port"],
				$this->_options["dbConfig"]["user"], 
				$this->_options["dbConfig"]["password"]);
		if (!$this->_options["dbConn"]) {
			die('Could not connect to database: ' . mysql_errno());
		}
		mysql_select_db($this->_options["dbConfig"]["database"], $this->_options["dbConn"]);
	}

	private function dbCloseConnection()
	{
		mysql_close($this->_options["dbConn"]);
	}
	
	public static function loadModules()
	{
		//membersModule::createMemberSession();
	}

}
?>